package edu.neu.highway.controller;

import com.alibaba.fastjson.JSON;
import edu.neu.highway.annotation.IgnoreResponseAdvice;
import edu.neu.highway.service.IFluxQueryService;
import edu.neu.highway.vo.flux.FluxQueryParams;
import edu.neu.highway.vo.flux.FluxQueryResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <h1>流量查询接口</h1>
 */

@RestController
@Api(tags = "流量查询")
@RequestMapping("/query-flow")
@Slf4j
public class FluxQueryController {

    private final IFluxQueryService fluxQueryService;


    public FluxQueryController(IFluxQueryService fluxQueryService) {
        this.fluxQueryService = fluxQueryService;
    }

    @PostMapping("/flux")
    @IgnoreResponseAdvice
    public FluxQueryResult queryByFlux(@RequestBody String fluxQuery) {
        log.info("query flux:\n{}", fluxQuery);
        return fluxQueryService.queryFlowByFlux(fluxQuery);
    }

    @ApiOperation(value = "流量查询", notes = "根据参数指定流量查询方法", httpMethod = "POST")
    @PostMapping("/params")
    public FluxQueryResult queryByParams(@RequestBody FluxQueryParams params) {
        log.info("start query, params:[{}]", JSON.toJSONString(params));
        return fluxQueryService.queryFlowByParams(params);
    }
}
